package com.me.study.designPatterns.Builder;

import org.junit.Test;

import java.util.Locale;

import static org.junit.Assert.assertTrue;

/**
 * 建造者模式：创建对象模式三剑客的第一种模式。Builder允许我们通过使用将值传递给父类的内部构建器对象来清楚地分解对象构造。<P>
 * spring 中的应用见：{@link org.springframework.beans.factory.support.BeanDefinitionBuilder}
 *
 * @author ME
 * @date   2019/5/7
 */
public class TestBuilder {

    @Test
    public void test() {
        String first = "F";
        String last = "L";
        Programmer programmer = new Programmer.ProgrammerBuilder()
                        .setFirstName(first).setLastName(last)
                        .setCity("City").setZipCode("0000A").setAddress("Street 39")
                        .setLanguages(new String[]{"bash", "Perl"})
                        .setProjects(new String[]{"Linux kernel"}).build();

        String assertStr = String.format(Locale.CHINESE, "%s.%s", first, last);
        assertTrue(String.format(Locale.CHINESE, "Programmer should be '%s' but was '%s'", assertStr, programmer),
            programmer.toString().equals(assertStr));

    }
}
